package ezCall;

import net.rim.device.api.system.Characters;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.ContextMenu;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.EditField;





public  class Find_Field extends BasicEditField
{   
	String _TitleInfo_Str;
	ezCall_Screen _ezCall_Screen;
	
    // Contructor
    public Find_Field( String label )
    {
        //super(USE_ALL_WIDTH|NON_FOCUSABLE|NO_LEARNING|NO_NEWLINE);
    	//super(NON_FOCUSABLE|NO_LEARNING|NO_NEWLINE);
    	super(label, "", 20, NON_FOCUSABLE|NO_LEARNING|NO_NEWLINE);
        setLabel(label);
        
        _TitleInfo_Str = new String();
    }
    
    public void Set_Screen( ezCall_Screen _Screen_Arg )
    {
    	_ezCall_Screen = _Screen_Arg;
    }    
    
    public void Set_TitleInforStr( String Str )
    {
    	_TitleInfo_Str = Str;
    }
    
    public void Remove_LastChar()
    {
        String Str     = getText();
    	
        if( getText().length() <= 0 ) return;
        
        Str = getText().substring(0, getText().length()-1);
        
        setText(Str);
        
        Str = null;
    }
    
    public boolean isDirty()
    {            
        return false;
    }      
    
    protected boolean keyChar(char ch, int status, int time)
    {
        switch(ch)
        {
            case Characters.ESCAPE:
                // Clear keyword.
                if(super.getTextLength() > 0)
                {
                    setText("");                        
                    return true;
                }
                break;
        }        
        
        super.keyChar(ch, status, time);

        return false; 
    }                     
    
    protected void paint(Graphics graphics)
    {   
    	XYRect _FocusRect = new XYRect();
    	
        super.paint(graphics);
        
        // Draw caret.
        getFocusRect(_FocusRect);
        drawFocus(graphics, true);   
        
       // _FocusRect.
        
        
        
        if( getText().length() > 0 )
        {
        	String Str = "["+String_Cho.Get_ToggledStr(getText())+"]";
        	
        	graphics.drawText( Str,_FocusRect.x+_FocusRect.width+3 ,_FocusRect.y );
        }
        //graphics.drawText(_TitleInfo_Str, 0, _TitleInfo_Str.length(),0,0, graphics.RIGHT , graphics.getScreenWidth() );        
       // graphics.drawRect(0, 0, getPreferredWidth()-1, getPreferredHeight() );
    }
    
    protected void layout(int width, int height )
    {
    	super.layout(getPreferredWidth(), height+50);
    	super.setExtent(getPreferredWidth(), getPreferredHeight()+8);
    }
	
    
    public int getPreferredWidth()
    {
    	return Graphics.getScreenWidth()*2/3;
    }    
}